/*
 * Layout.h
 *
 *  Created on: 2012-10-24
 *      Author: yangentao@gmail.com
 */

#ifndef LAYOUT_H_
#define LAYOUT_H_

#include "Graphic.h"

#define FILL_PARENT 	-1
#define WRAP_CONTENT 	-2 //not implement

class Window;

class MarginPadding {
public:
	MarginPadding();
	virtual ~MarginPadding();
public:
	void setMargin(int margin);
	void setMargin(int leftRight, int topBottom);
	void setMargin(int left, int right, int top, int bottom);
	void setPadding(int padding);
	void setPadding(int leftRight, int topBottom);
	void setPadding(int left, int right, int top, int bottom);

public:
	//margin,  may <0, use when been layout
	int marginLeft;
	int marginRight;
	int marginTop;
	int marginBottom;
	//padding >=0, used by layout container when layout children
	int paddingLeft;
	int paddingRight;
	int paddingTop;
	int paddingBottom;
};

enum AlignValue {
	alignCenter,
	alignLeft,
	alignRight,
	alignTop,
	alignBottom,
};

//class LayoutAnchor{
//public:
//	LayoutAnchor();
//
//	Window* anchor;//0: cell;  other: anchor window
//};
enum LayoutParamType {
	noneLayoutParam,
	linnerLayoutParam,
	relativeLayoutParam,
};

class LinnerParam;
class RelativeParam;

class LayoutParam: public MarginPadding {
public:

public:
	LayoutParam();
	bool isRelative();
	bool isLinner();
	bool isNoneLayoutParam();
	bool isType(LayoutParamType type);
	LinnerParam* toLinner();
	RelativeParam* toRelative();
protected:
	LayoutParamType type;
public:
	bool enable; //enable layout or not

};

class LinnerLayout;
class RelativeLayout;

class Layout {
public:
	virtual ~Layout();
	virtual void layout(Window* parent);

};

//====================================================================

inline LayoutParam::LayoutParam() {
	type = noneLayoutParam;
	enable = true;
}
inline LinnerParam* LayoutParam::toLinner(){
	assert(isLinner());
	return (LinnerParam*)this;
}

inline RelativeParam* LayoutParam::toRelative(){
	assert(isRelative());
	return (RelativeParam*)this;
}
inline bool LayoutParam::isType(LayoutParamType type_){
	return type == type_;
}
inline bool LayoutParam::isRelative() {
	return type == relativeLayoutParam;
}
inline bool LayoutParam::isLinner() {
	return type == linnerLayoutParam;
}
inline bool LayoutParam::isNoneLayoutParam() {
	return type == noneLayoutParam;
}



inline MarginPadding::MarginPadding() {
	setMargin(0);
	setPadding(0);
}
inline void MarginPadding::setMargin(int margin) {
	marginLeft = marginRight = marginTop = marginBottom = margin;
}

inline void MarginPadding::setPadding(int padding) {
	paddingLeft = paddingRight = paddingTop = paddingBottom = padding;
}
inline void MarginPadding::setMargin(int leftRight, int topBottom) {
	marginLeft = marginRight = leftRight;
	marginTop = marginBottom = topBottom;
}
inline void MarginPadding::setMargin(int left, int right, int top, int bottom) {
	marginLeft = left;
	marginRight = right;
	marginTop = top;
	marginBottom = bottom;
}
inline void MarginPadding::setPadding(int leftRight, int topBottom) {
	paddingLeft = paddingRight = leftRight;
	paddingTop = paddingBottom = topBottom;
}
inline void MarginPadding::setPadding(int left, int right, int top, int bottom) {
	paddingLeft = left;
	paddingRight = right;
	paddingTop = top;
	paddingBottom = bottom;
}

#endif /* LAYOUT_H_ */
